<style>
    .layui-form-label {
        width: 100px;
    }
    .layui-input-block {
        margin-left: 130px;
    }
</style>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label">创建时间：</label>
                                    <div class="layui-input-inline">
                                        <input name="createTime" id="pTime" class="layui-input" type="text"
                                               placeholder="选择时间" autocomplete="off" style="width: 200px" readonly/>
                                    </div>
                                    <input name="startTime" id="startTime" type="hidden"/>
                                    <input name="endTime" id="endTime" type="hidden"/>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">柜子编号：</label>
                                    <div class="layui-input-inline">
                                        <select  name="cabCode" lay-filter="cabCode"  lay-search lay-verify="" class="common-select-search">
                                            <option value="">请选柜子</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">盘验任务编号：</label>
                                    <div class="layui-input-inline">
                                        <input name="code" class="layui-input" type="text" placeholder="请输入盘验任务编号" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">货位编号:</label>
                                    <div class="layui-input-inline">
                                        <input name="spaceCode" class="layui-input" type="text" placeholder="请输入货位编号" autocomplete="off"/>
                                    </div>
                                </div>
                            </div>
                            <div class="query-rt">
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit layui-form-keyDownSearch="true">查询</button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="lay-btn-rows">
                    <div class="lay-btn-box">
                        <div class="lay-btn-lt">
                            <button id="storageInventoryInoutBtnExport" class="layui-btn icon-btn color-green">导出
                            </button>
                        </div>
                        <div class="lay-btn-rt">

                        </div>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="storageInventoryInoutTable" lay-filter="storageInventoryInoutTable"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="storageInventoryInoutTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>
    {{# if(d.status=='created'){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="open">开柜</a>
    <a class="layui-btn layui-btn-xs" lay-event="check">盘验</a>
    {{#} }}
    {{# if(d.status!='created'){ }}
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="checkResult">盘验结果</a>
    {{#} }}
    <!--
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    -->
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="storageInventoryInoutForm">
    <form lay-filter="storageInventoryInoutForm" class="layui-form model-form form-scroll">
        <div class="open-details-box pd-20 is-detail">
            <input name="id" type="hidden"/>
            <div class="color-title" style="margin: 15px 0;">盘验任务信息</div>
            <div class="layui-form-item">
                <div class="layui-col-md4">
                    <label class="layui-form-label">柜子名称</label>
                    <div class="layui-input-block">
                        <input name="cabName" placeholder="" type="text" class="layui-input" lay-verify="required" required/>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <label class="layui-form-label">柜子编号</label>
                    <div class="layui-input-block">
                        <input name="cabCode" placeholder="" type="text" class="layui-input" lay-verify="required" required/>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <label class="layui-form-label">所属货位</label>
                    <div class="layui-input-block">
                        <input name="spaceCode" placeholder="" type="text" class="layui-input" lay-verify="required" required/>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-col-md4">
                    <label class="layui-form-label">盘验任务编号</label>
                    <div class="layui-input-block">
                        <input name="code" placeholder="" type="text" class="layui-input" lay-verify="required" required/>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <label class="layui-form-label">订单创建时间</label>
                    <div class="layui-input-block">
                        <input name="createTime" placeholder="" type="text" class="layui-input" lay-verify="required" required/>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <label class="layui-form-label">存储性质</label>
                    <div class="layui-input-block">
                        <input name="businessTypeDesc" placeholder="" type="text" class="layui-input" lay-verify="required" required/>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-col-md4">
                    <label class="layui-form-label">盘验订单状态</label>
                    <div class="layui-input-block">
                        <input name="statusDesc" placeholder="" type="text" class="layui-input" lay-verify="required" required/>
                    </div>
                </div>
            </div>
            <div class="color-title" style="margin: 15px 0;">设备信息</div>
            <div class="layui-form-item">
                <div class="layui-col-md4">
                    <label class="layui-form-label">所属企业</label>
                    <div class="layui-input-block">
                        <input name="enterpriseName" placeholder="" type="text" class="layui-input" lay-verify="required" required/>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <label class="layui-form-label">所属车间</label>
                    <div class="layui-input-block">
                        <input name="workshopName" placeholder="" type="text" class="layui-input" lay-verify="required" required/>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <label class="layui-form-label">车间描述</label>
                    <div class="layui-input-block">
                        <input name="workshopDesc" placeholder="" type="text" class="layui-input" lay-verify="required" required/>
                    </div>
                </div>
            </div>
            <div class="color-title" style="margin: 15px 0;">物料信息</div>
            <table class="layui-table" id="storageInventoryInoutDetailTable" lay-filter="storageInventoryInoutDetailTable"></table>
            <div id="businessTypeDiv">
                <div class="layui-form-item" >
                    <label class="layui-form-label">核验结果</label>
                    <!--
                    <div class="layui-input-block">
                        <select name="isCorrect">
                            <option value="1">相符</option>
                            <option value="0">不相符</option>
                        </select>
                    </div>
                    -->
                    <div class="layui-input-block">

                        <input type="radio" name="isCorrect" value="1" lay-filter="isCorrect" title="相符" checked/>
                        <input type="radio" name="isCorrect" value="0" lay-filter="isCorrect" title="不相符" />
                        <input type="radio" name="isCorrect" value="3" lay-filter="isCorrect" title="物料不相符" />
                        <input type="radio" name="isCorrect" value="2" lay-filter="isCorrect" title="缺失" />
                    </div>
                </div>
                <div class="layui-form-item" id="categoryDiv">
                    <label class="layui-form-label">不相符分类</label>
                    <input name="categoryId" type="hidden"/>
                    <div class="layui-input-block" id="selectCategory">
                    </div>
                </div>
                <div class="layui-form-item" id="businessTypeDiv2">
                    <label class="layui-form-label">修正状态</label>
                    <div class="layui-input-block">
                        <select name="businessType">
                            <option value="repair">报修</option>
                            <option value="temp">暂存</option>
                            <option value="recycle">报废</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item text-right pd-20">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn saveCancelBtn" lay-filter="storageInventoryInoutFormSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin', 'laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        var laydate = layui.laydate;

        admin.selectSearch();

        // 渲染表格
        var insTb = table.render({
            elem: '#storageInventoryInoutTable',
            // url: config.base + 'enterprisecab/cabinet/admin/storageCheckInventoryIn/list',
            url: config.base + 'enterprisecab/cabinet/admin/storageInventoryCheck/list?status=created',
            toolbar: true,
            defaultToolbar: ["filter"],
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers', title: '序号', fixed: 'left'}
                ,{field: 'code', sort: true, title: '盘验任务编号', width: 160}
                ,{field: 'cabCode', sort: true, title: '柜子编号', width: 160}
                ,{field: 'spaceCode', sort: true, title: '货位编号'}
                ,{field: 'quantity', title: '数量'}
                ,{field: 'businessType', sort: true, title: '存储性质',templet:function (d) {
                        if(d.businessType=='temp'){
                            return '暂存';
                        }else if(d.businessType=='repair'){
                            return '报修'
                        }else if(d.businessType=='recycle'){
                            return '报废'
                        }
                    }}
                ,{field: 'creatorName', sort: true, title: '责任人', width: 110}
                ,{field: 'createTime', sort: true, title: '创建时间', width: 160}

                ,{field: 'status', sort: true, title: '盘验状态',templet:function (d) {
                        if(d.status=='created'){
                            return '待盘验'
                        }
                        return  '已盘验'
                    }}
                // ,{field: 'no', sort: true, title: 'no'}
                // ,{field: 'day', sort: true, title: 'day'}
                // ,{field: 'operationTypeDesc', sort: true, title: '操作类型'}
                // ,{field: 'businessTypeDesc', sort: true, title: '业务类型'}
                // ,{field: 'statusDesc', sort: true, title: '状态'}
                // ,{field: 'checkTime', sort: true, title: '盘验时间'}
                // ,{field: 'checkUserId', sort: true, title: '盘验人id'}
                // ,{field: 'checkUserName', sort: true, title: '盘验人'}
                // ,{field: 'notifyTime', sort: true, title: '通知时间'}
                // ,{field: 'notifyUserId', sort: true, title: '通知人'}
                // ,{field: 'notifyUserName', sort: true, title: '通知人'}
                // ,{field: 'takeUserId', sort: true, title: '回收人id'}
                // ,{field: 'takeUserName', sort: true, title: '回收人'}
                // ,{field: 'takeTime', sort: true, title: '回收时间'}
                // ,{field: 'inoutId', sort: true, title: '暂存柜存刀id'}
                // ,{field: 'cabId', sort: true, title: '柜子id'}
                // ,{field: 'skuId', sort: true, title: 'sku id'}
                // ,{field: 'companyId', sort: true, title: '企业id'}
                // ,{field: 'spaceId', sort: true, title: '货道id'}
                // ,{field: 'operationTypeDesc', sort: true, title: '操作类型'}
                // ,{field: 'businessTypeDesc', sort: true, title: '业务类型'}
                // ,{field: 'quantityCurrent', sort: true, title: '当前库存'}
                // ,{field: 'quantityAfter', sort: true, title: '变动后库存'}

                ,{align: 'center', fixed: 'right', toolbar: '#storageInventoryInoutTableBar', title: '操作', width: 180}
            ]],
            done: function (res, curr, count) {
                //移除按钮
                var menuButton = config.getMenuButton(location.hash);
                if(menuButton.indexOf("搜索") == -1){
                    $('.layui-form.toolbar').remove();
                }
                if(menuButton.indexOf("修改") == -1){
                    $("[lay-event='edit']").remove();
                }
                if(menuButton.indexOf("删除") == -1){
                    $("[lay-event='del']").remove();
                }
            }
        });

        // 工具条点击事件
        table.on('tool(storageInventoryInoutTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') { //修改
                showEditModel(data);
            } else if (obj.event === 'del') { // 删除
                doDelete(obj);
            }else if(obj.event=='detail'||obj.event=='check'||obj.event=='checkResult'){
                admin.req('enterprisecab/cabinet/admin/storageInventoryCheck/detail/' + obj.data.id, {}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        res.data.eventType=obj.event;
                        showEditModel(res.data);
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'GET');
            }else if(obj.event=='open'){
                layer.confirm('确定要开柜吗？', {
                    offset: '65px',
                    skin: 'layui-layer-admin'
                }, function (i) {
                    layer.close(i);
                    layer.load(2);
                    admin.req('enterprisecab/cabinet/websocket/cabinetOpen/open' , {cabCode:data.cabCode,spaceCode:data.spaceCode}, function (res) {
                        layer.closeAll('loading');
                        if (res.code == 200) {
                            layer.msg(res.msg, {icon: 1});
                        } else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }, 'GET');
                });
            }

        });

        //监听排序
        table.on('sort(storageInventoryInoutTable)', function(obj){
            table.reload('storageInventoryInoutTable', {
                initSort: obj
                ,where: {
                    sort: obj.field
                    ,order: obj.type
                }
            });
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field,page: {curr: 1}},'data');
        });

        // 重置搜索
        form.on('submit(resets)', function (data) {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            let field = data.field;
            for (let key in field) {
                field[key] = ''
            }
            insTb.reload({where: field, page: {curr: 1}}, 'data');
        });

        admin.req('enterprisecab/cabinet/admin/cabinet/list', {limit:999,cabinetNature:'live'}, function (res) {
            if (200 == res.code) {
                var optionHtml='<option value=""> 请选择柜子</option>';
                for(var k=0;k<res.data.length;k++){
                    optionHtml+='<option value="'+res.data[k].code+'">'+res.data[k].code+'</option>';
                }
                $("select[name='cabCode']").html(optionHtml);
                form.render('select')
            } else {
                layer.msg(res.msg, {icon: 2, time: 1000});
            }
        }, 'GET');

        form.render('select');

        // 添加按钮点击事件
        $('#storageInventoryInoutBtnAdd').click(function () {
            showEditModel();
        });

        // 显示编辑弹窗
        function showEditModel(data) {
            var title='详情';
            if(data.eventType=='check'){
                title='盘验';
            }else if(data.eventType=='checkResult'){
                title='盘验结果'
            }
            admin.open({
                type: 1,
                area: ['1280px', '800px'],
                offset: '65px',
                title: title,
                content: $('#storageInventoryInoutForm').html(),
                success: function () {
                    if(data.eventType=='detail'||data.eventType=='checkResult'){
                        $("#businessTypeDiv").hide();
                        $(".saveCancelBtn").hide();
                    }
                    if(data.eventType=='checkResult'||(data.eventType=='detail'&&data.status!='created')){
                        var html='<div class="layui-form-item">\n' +
                            '            <label class="layui-form-label">盘验结果</label>\n' +
                            '            <div class="layui-input-block">\n' +
                            '                <input name="businessTypeCheckedDesc" placeholder="" type="text" class="layui-input" lay-verify="required" required/>\n' +
                            '            </div>\n' +
                            '        </div>'
                        html+='<div class="layui-form-item">\n' +
                            '            <label class="layui-form-label">盘验人</label>\n' +
                            '            <div class="layui-input-block">\n' +
                            '                <input name="checkUserName" placeholder="" type="text" class="layui-input" lay-verify="required" required/>\n' +
                            '            </div>\n' +
                            '        </div>'
                        html+='<div class="layui-form-item">\n' +
                            '            <label class="layui-form-label">盘验时间</label>\n' +
                            '            <div class="layui-input-block">\n' +
                            '                <input name="checkTime" placeholder="" type="text" class="layui-input" lay-verify="required" required/>\n' +
                            '            </div>\n' +
                            '        </div>'
                        $("#storageInventoryInoutDetailTable").after(html);
                    }
                    if (data){
                        var option = $("form select[name='operationType']").find("option");
                        layui.each(option, function(index, item){
                            if(data.operationType  == item.text){
                                data.operationType = item.value;
                            }
                        });
                    }

                    if (data){
                        var option = $("form select[name='businessType']").find("option");
                        layui.each(option, function(index, item){
                            if(data.businessType  == item.text){
                                data.businessType = item.value;
                            }
                        });
                    }

                    if (data){
                        var option = $("form select[name='status']").find("option");
                        layui.each(option, function(index, item){
                            if(data.status  == item.text){
                                data.status = item.value;
                            }
                        });
                    }

                    $(".model-form input").css("border","none")
                    $(".model-form input").attr('readonly',true);
                    $(".model-form input").removeAttr('lay-verify','required')
                    var currentPageData=[];
                    var insTb = table.render({
                        elem: '#storageInventoryInoutDetailTable',
                        // url: config.base + 'enterprisecab/cabinet/admin/storageInventoryInoutDetail/list?inoutId='+data.id,
                        url: config.base + 'enterprisecab/cabinet/admin/storageInventoryCheckDetail/list?checkId='+data.id,
                        // url: config.base + 'enterprisecab/cabinet/admin/storageInventoryKnife/list?cabCode='+data.cabCode+'&spaceCode='+data.spaceCode,
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'checkbox'}
                            ,{field: 'cabCode', sort: true, title: '所属柜子'}
                            ,{field: 'spaceCode', sort: true, title: '所属货位'}
                            ,{field: 'skuPic', sort: true, title: '物料图片',templet:function (d) {
                                    if(d.skuPic){
                                        return '<img src="'+ d.skuPic +'" style="height: 20px;"/>';
                                    }
                                    return '';
                                }}
                            ,{field: 'skuCode', sort: true, title: '物料编号'}
                            ,{field: 'skuName', sort: true, title: '物料名称'}
                            ,{field: 'skuSpecOld', sort: true, title: '规格'}
                            ,{field: 'productBrandName', sort: true, title: '品牌'}
                            ,{field: 'labelCode', sort: true, title: '唯一码'}
                            // ,{field: 'checkCode', sort: true, title: '盘验编号'}
                            ,{field: 'createTime', sort: true, title: '创建时间', width: 170}

                        ]],
                        done: function (res, curr, count) {
                            currentPageData=res.data;
                            //移除按钮
                            var menuButton = config.getMenuButton(location.hash);
                            if(menuButton.indexOf("搜索") == -1){
                                $('.layui-form.toolbar').remove();
                            }
                            if(menuButton.indexOf("修改") == -1){
                                $("[lay-event='edit']").remove();
                            }
                            if(menuButton.indexOf("删除") == -1){
                                $("[lay-event='del']").remove();
                            }
                        }
                    });

                    var checkedMap=new Map();
                    var checkedData=[];
                    table.on('checkbox(storageInventoryInoutDetailTable)', function(obj){
                        var data = obj.data;
                        if(obj.type=='all'){
                            if(obj.checked){
                                var checkStatus = table.checkStatus('storageInventoryInoutDetailTable')
                                var checkedAllData = checkStatus.data;
                                checkedAllData.forEach(item=> {
                                    if(!item.isGenOrder){
                                        if (checkedMap.get(item.id) == undefined) {
                                            checkedData.push(item);
                                        }
                                        checkedMap.set(item.id,item.id);
                                    }

                                })


                            }else{
                                currentPageData.forEach(item=>{
                                    if(checkedMap.get(item.id)!=undefined){
                                        checkedData=checkedData.filter(item2=>{
                                            if(item.id==item2.id){
                                                return false;
                                            }
                                            return  true;
                                        })
                                    }
                                    checkedMap.delete(item.id);

                                })
                            }
                        }else{
                            if(obj.checked){
                                if (checkedMap.get(data.id) == undefined) {
                                    checkedData.push(data);
                                }
                                checkedMap.set(data.id,data.id);
                            }else{
                                if(checkedMap.get(data.id)!=undefined){
                                    checkedData=checkedData.filter(item=>{
                                        if(item.id==data.id){
                                            return false;
                                        }
                                        return  true;
                                    })
                                }
                                checkedMap.delete(data.id);
                            }
                            var isAllChecked=true;
                            currentPageData.forEach(item=>{
                                if(!item.isGenOrder){
                                    if(checkedMap.get(item.id)==undefined){
                                        isAllChecked=false;
                                    }
                                }

                            })
                            if(isAllChecked){
                                $('[lay-filter="layTableAllChoose"]').prop('checked', true).next().addClass('layui-form-checked');
                            }else{
                                $('[lay-filter="layTableAllChoose"]').prop('checked', false).next().removeClass('layui-form-checked');
                            }
                        }

                    });



                    var treeData=[];
                    admin.req('enterprisecab/setting/admin/businessClassifySet/getTreeDataByParentCode', {limit:9999,parentCode:'CHECK'}, function (res) {
                        if ( res.code==200) {
                            treeData=res.data;
                        } else {
                            layer.msg('获取分类失败', {icon: 2, time: 1000});
                        }
                    }, 'GET',false);

                    var selectedData=function(treeData,targetId){
                        for(var k=0;k<treeData.length;k++){
                            var nodeId=treeData[k].value;
                            if(targetId==nodeId){
                                treeData[k].selected=true;
                                return;
                            }else{
                                if(treeData[k].children&&treeData[k].children!=''){
                                    selectedData(treeData[k].children,targetId);
                                }
                            }
                        }
                    }

                    if(data&&data.eventType=='editAttr'){
                        selectedData(treeData,data.categoryId);
                    }

                    var businessType=data.businessType;

                    xmSelect.render({
                        el: '#selectCategory',
                        model: {label: {type: 'text'}},
                        radio: true,
                        clickClose: true,
                        filterable: true,
                        tree: {
                            show: true,
                            strict: false,
                            expandedKeys: [-1],
                        },
                        tips: '顶级分类',
                        height: 'auto',
                        data() {

                            return treeData;
                        },
                        on: function (data) {
                            //被选中的select的id,如果没有 -1
                            let parentId = data.arr.length > 0 ? data.change[0].value : -1;
                            $("input[name='categoryId']").val(parentId);
                            if(data.change[0].code=='STATE_ERROR'){
                                // $("#businessTypeDiv2").show();
                                // var businessTypeHtml=''
                                // if(businessType=='temp'){
                                //     businessTypeHtml='<option value="repair">报修</option>\n' +
                                //         '                        <option value="recycle">报废</option>';
                                // }else if(businessType=='repair'){
                                //     businessTypeHtml=
                                //         '                        <option value="temp">暂存</option>\n' +
                                //         '                        <option value="recycle">回收/报废</option>';
                                // }else if(businessType=='recycle'){
                                //     businessTypeHtml='<option value="repair">报修</option>\n' +
                                //         '                        <option value="temp">暂存</option>\n' ;
                                // }
                                // $("form select[name='businessType']").html(businessTypeHtml);
                                // form.render('select')
                            }else{
                                // $("#businessTypeDiv2").hide();
                            }
                        },
                    });

                    if(data){
                        $("#categoryDiv").hide();
                        $("#businessTypeDiv2").hide();
                        var ele=$("#selectCategory");
                        var eleChild=ele[0].children[0].children[0]
                        if(eleChild){
                            $(eleChild).removeAttr('lay-verify');
                        }
                    }


                    form.on('radio(isCorrect)',function(data){

                        if(data.value==1||data.value==2||data.value==3){
                            $("#categoryDiv").hide();
                            $("#businessTypeDiv2").hide();
                            var ele=$("#selectCategory");
                            var eleChild=ele[0].children[0].children[0]
                            if(eleChild){
                                $(eleChild).removeAttr('lay-verify');
                            }

                        }else{
                            $("#categoryDiv").show();
                            $("#businessTypeDiv2").show();
                            var ele=$("#selectCategory");
                            var eleChild=ele[0].children[0].children[0]
                            if(eleChild){
                                $(eleChild).attr('lay-verify','required');
                            }
                            var businessTypeHtml=''
                            if(businessType=='temp'){
                                businessTypeHtml='<option value="repair">报修</option>\n' +
                                    '                        <option value="recycle">报废</option>';
                            }else if(businessType=='repair'){
                                businessTypeHtml=
                                    '                        <option value="temp">暂存</option>\n' +
                                    '                        <option value="recycle">回收/报废</option>';
                            }else if(businessType=='recycle'){
                                businessTypeHtml='<option value="repair">报修</option>\n' +
                                    '                        <option value="temp">暂存</option>\n' ;
                            }
                            $("form select[name='businessType']").html(businessTypeHtml);
                            form.render('select')
                        }
                    })

                    console.log("-------------------------");
                    console.log(data);
                    console.log("-------------------------");
                    form.val('storageInventoryInoutForm', data);
                    // 表单提交事件
                    form.on('submit(storageInventoryInoutFormSubmit)', function (d) {
                        var isCorrect=$("form input[name='isCorrect']:checked").val();
                        var businessType=$("form select[name='businessType']").val();
                        if(checkedData.length==0){
                            layer.msg('请选盘验记录', {icon: 2})
                            return false;
                        }
                        if(checkedData.length>1&&isCorrect=='0'&&businessType=='temp'){
                            layer.msg('盘验成暂存只能选取一把刀具', {icon: 2})
                            return false;
                        }
                        layer.load(2);

                        if(isCorrect=='2'){
                            d.field.isCorrect=false;
                            d.field.businessType='losed';
                            d.field.flag=false;
                        }else if(isCorrect=='3'){
                            d.field.isCorrect=false;
                            d.field.skuFlag=true;
                            d.field.flag=false;
                            d.field.businessType=data.businessType;
                        }else if(isCorrect=='1'){
                            d.field.isCorrect=true;
                            d.field.businessType=data.businessType;
                        }else if(isCorrect=='0'){
                            d.field.isCorrect=false;

                        }
                        d.field.orderId=d.field.id
                        d.field.detailList=checkedData;

                        admin.req('enterprisecab/cabinet/admin/storageInventoryInoutDetail/check4web', JSON.stringify(d.field), function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('storageInventoryInoutTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST', true, 'application/json; charset=utf-8');
                        return false;
                    });
                }
            });
        }

        // 删除
        function doDelete(obj) {
            layer.confirm('确定要删除吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('enterprisecab/cabinet/admin/storageInventoryInout/' + obj.data.id, {}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        obj.del();
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'DELETE');
            });
        }

        // 导出excel
       /* $('#storageInventoryInoutBtnExport').click(function () {
            var checkRows = table.checkStatus('storageInventoryInoutTable');
            if (checkRows.data.length == 0) {
                layer.msg('请选择要导出的数据', {icon: 2});
            } else {
                table.exportFile(insTb.config.id, checkRows.data, 'xls');
            }
        });*/

        //时间范围
        laydate.render({
            elem: '#pTime',
            type: 'date',
            range: true,
            done: function (value, date, endDate) {
                if(value){
                    let dateValue = value.split(" - ");
                    $("#startTime").val(dateValue[0]+" 00:00:00");
                    $("#endTime").val(dateValue[1]+" 23:59:59");
                }else {
                    $("#startTime").val("");
                    $("#endTime").val("");
                }
                setTimeout(function() {$('[lay-filter="formSubSearchLog"]').click()}, 300);
            }
        });

        // 导出
        $('#storageInventoryInoutBtnExport').click(function () {
            var sTime = $('#startTime').val();
            var eTime = $('#endTime').val();

            if (sTime == "" && eTime == ""){
                layer.msg('请先选择时间！')
            } else {

                location.href = config.base + 'enterprisecab/cabinet/admin/storageInventoryCheck/export?startCreateTime='+sTime+'&endCreateTime='+eTime+ '&enterpriseCode=' + config.getUser().enterpriseCode;
            }
        });

    });
</script>